
<template>
    <div>
        <main-view
            :dataList="getDataList"
            :currentPage="currentPage"
            :isNullData="isNullData"
            @changeTab="changeTab"
            @onDelete="onDelete"
        ></main-view>
        <xszk-pop-comfirm
            :isPopShow="isPopShow"
            :popCont="popCont"
            @cancelPop="isPopShow=false"
            @comfirmPop="comfirmPop"
        ></xszk-pop-comfirm>
    </div>
</template>

<script>
export default {
    name: "note",
    components:{
        mainView: (resolve) =>require([ "./components/mainView",], resolve),
        xszkPopComfirm: (resolve) =>require([ "../../components/xszkPopComfirm",], resolve),
    },
    computed: {
       
    },
    data() {
        return {
            isNullData:false,
            classType:1,
            getDataList:[],
            currentPage: {
                page: 1,
                size: 10,
                total: 0,
            },
            isPopShow:false,
            popCont:'笔记删除后无法恢复，确认删除？',
            currId:'',
            
        };

    },
    methods: {
        initDataList(){
            this.isNullData = false;
            this.currentPage.page = 1;
            this.getNote();
        },
        onDelete(id){
            this.currId = id;
            this.isPopShow = true;
        },
        comfirmPop(){
            let that = this;
            let data = `id[0]=${this.currId}`
            this.request.delNote(data, function (res) {
                if (res.code == "0") {
                    that.isPopShow = false;
                    that.toast.success("删除成功");
                    that.initDataList();
                } else {
                    that.toast.error(res.message);
                }
            });
        },
        changeTab(index){
            this.classType = index;
            this.initDataList();
        },
        getNote(){
            let that = this;
            let data = {
                data_base_type:this.classType
            }
            this.request.getNote(data, function (res) {
                if (res.code == "0") {
                    that.getDataList = [];
                    let resData = res.data;
                    if(resData.length!=0){
                        that.currentPage.total = resData.length;
                        that.getDataList = resData;
                        console.log(that.getDataList);
                    }else{
                        that.isNullData = true;
                    }
                    
                } else {
                    that.toast.error(res.message);
                }
            });
        },
      
    },
   
    created() {
        this.getNote();
    },
    
    

};
</script>

<style lang="stylus" scoped>
   
</style>